package com.ruoyi.heima.listener;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.IndexRequest;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.heima.constants.Mqconstant;
import com.ruoyi.heima.domain.vo.NewsVo;
import com.ruoyi.heima.mapper.TbNewsMapper;
import com.ruoyi.heima.service.ITbNewsService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class DelayListener {

    @Autowired
    private TbNewsMapper tbNewsMapper;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = Mqconstant.DLQ_QUEUE,durable = "true"),
            exchange = @Exchange(value = Mqconstant.DLQ_EXCHANGE,type = ExchangeTypes.TOPIC,delayed = "true"),
            key = Mqconstant.NEWS_DLQ_KEY
    ))
    public void dlqListener(String newsId){
         tbNewsMapper.publishNews(Long.parseLong(newsId));
    }
}
